package SqlTest;

import java.sql.*;

public class TestTwo {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement=null;
        ResultSet resultSet=null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/j180?useSSL=false&serverTimezone=Asia/Shanghai","root","994152993");
            String sql="select * from t_student";
            statement=connection.createStatement();
            resultSet=statement.executeQuery(sql);
            while (resultSet.next()){
                int id=resultSet.getInt("_id");
                String name=resultSet.getString("_name");
                int age=resultSet.getInt("_age");
                String gender=resultSet.getString("_sex");
                String job=resultSet.getString("_code");
                System.out.println(id+" "+name+" "+age+" "+gender+" "+job);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (connection!=null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (statement!=null){
                try {
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (resultSet!=null){
                try {
                    resultSet.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
